var app = getApp();
var WxParse = require('../../wxParse/wxParse.js');
var Data = require('../../utils/data.js');
var common = require("../../utils/common.js")  
var page_size=50,page = 1,keyword='',that,ora_quantity,service_charge;

var getNo = function(that){
	Data.httpGet(
	   		 { action: 'getAccountInfo', account_id: common.getStorage('user_id')},
	   		 function (res) {
             ora_quantity = res.data.data[0]['ora_quantity'];
	   			 that.setData({
               ora_quantity: res.data.data[0]['ora_quantity'],
	   			 });
	   		 }
	);
}

Page({

  /**
   * 页面的初始数据
   */
  data: {
	  ora_quantity:0,
	  service_charge:'0.00 Ejoy'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	  that = this;
	  
	  wx.setNavigationBarTitle({
	     title: '转出到imToken钱包'
	  });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
	  getNo(that);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },
  
  oraout:function(e){
	  wx.navigateTo({
		  url:'../oraout/oraout'
	  })
  },
  
  bindinputchange:function(e){
	  var ora_quantity_get = e.detail.value;
	  service_charge = Math.floor(ora_quantity_get*0.1* 100) / 100 +' Ejoy Fit'  ;
	  that.setData({
		  service_charge:service_charge
	  })
  },
  
  formSubmit: function(e) {
		var info = e.detail.value;
		if(info.imtoken_url==''){
			common.showError('请填写imToken钱包地址');
			return false;
		}
		if(info.ora_quantity_get==''){
			common.showError('请填写数量');
			return false;
		}
		if(info.ora_quantity_get < 100){
			common.showError('提现数量需大于100');
			return false;
		}
		
		if(info.ora_quantity_get > ora_quantity){
			common.showError('数量不能大于可提现总数');
			return false;
		}
		
		var ora_quantity_get = info.ora_quantity_get*100;
		var service_charge = info.service_charge*100;
		
		common.wxshowLoading();
		Data.httpGet(
      		 { action: 'setImToken',imtoken_url:info.imtoken_url,ora_quantity:ora_quantity_get,service_charge:service_charge},
      		 function (res) {
      			 common.wxhideLoading();
      			 if(res.data.status=='y'){
      				 common.showInfo('恭喜您，转出成功',
      						function(){
      							wx.switchTab({url: '../asset/asset'});
      						}	
      				 );
      			 }else{
      				 common.showError(res.data.info);
      				 return false;
      			 }
      		 }
       );
		
	},
})